package cn.edu.demo.controller;

import cn.edu.demo.pojo.Orders;
import cn.edu.demo.pojo.OrdersWithBLOBs;
import cn.edu.demo.pojo.Passenger;
import cn.edu.demo.pojo.ResponseResult;
import cn.edu.demo.pojo.result.LoginResult;
import cn.edu.demo.pojo.result.OrderlistResult;
import cn.edu.demo.pojo.result.StartResult;
import cn.edu.demo.service.CarService;
import cn.edu.demo.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import sun.text.resources.ro.JavaTimeSupplementary_ro;


@RestController
@CrossOrigin
//@Controller
public class OrdersController {

    @Autowired
    OrdersService ordersService;

    @Autowired
    CarService carService;

    /*
    发起订单
     */
    @RequestMapping("/user/start")
    @ResponseBody
    public ResponseResult startOrder(String uid, String s_point, String s_position, String e_point, String e_position, String s_time, String s_path, String model){
        //获取最新的订单号
        String lastOid = ordersService.getLastOid();
        //订单号加一
        long newOid = Integer.valueOf(lastOid) + 1;
        //计算车费
        double price = Double.valueOf(s_path) * 1.5;

        String carnum = "aaa";

        ordersService.newOrder(new OrdersWithBLOBs());
        return new ResponseResult(100,"发起订单成功",new StartResult(newOid+"",price+"",carnum));
    }
    /*
    支付订单
     */
    @RequestMapping("/user/pay")
    @ResponseBody
    public ResponseResult payOrder(String o_id, String money){
        if(ordersService.payOrder(o_id,money))
            return new ResponseResult(120,"支付成功",null);
        else
            return new ResponseResult(121,"支付失败",null);
    }


}
